#!/bin/bash
PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
export PATH

script=$PWD/$0
path=$(dirname $script)
work_path=$(dirname $path)
docker_path=$work_path/docker
mysql_path=$docker_path/mysql

echo --- init mysql start ---
cd $docker_path && tar -xzvf mysql.tar.gz 
echo "chmod -R 777 $mysql_path/data";
chmod -R 777 $mysql_path/data
echo "chmod -R 777 $mysql_path/log";
chmod -R 777 $mysql_path/log
echo --- init mysql end ---


echo --- project set host start ---
server_file=$docker_path/bt/conf/server_ip
server_conf=$docker_path/bt/conf/127.0.0.1.conf
rm -rf $server_conf
cp $server_conf.bk $server_conf
echo -n 'server_name=' > $server_file
wget http://ipecho.net/plain -O - -q  >> $server_file
source $docker_path/bt/conf/server_ip
sed -i "s/255.255.255.255/$server_name/g" $server_conf
rm -rf $server_file
echo --- project set host end ---

echo --- ssh key start ---
mkdir ~/.ssh
cat $path/works.pub >  ~/.ssh/authorized_keys
cat  ~/.ssh/authorized_keys
echo --- ssh key end ---